﻿using System.Collections.Generic;
using System.Data;

using Dapper.Common;

namespace DapperExtensions
{
    public interface IRepository<T>
    {
        /// <summary>
        /// List<ISort> sortList = new List<ISort>();  //排序
        /// sortList.Add(Predicates.Sort<myPoco>(x => x.Name, false));
        /// var result = GetList<myPoco>(null, sortList).ToList();
        /// return result;
        /// protected IEnumerable<T> GetList<T>(object predicate, IList<ISort> sort = null, 
        ///   IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class {
        ///   var result = connection.GetList<T>(predicate, sort, transaction, commandTimeout, buffered);
        ///   return result;
        /// }
        /// </summary>
        /// <param name="predicate">参数： var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true);</param>
        /// <param name="sort"></param>
        /// <param name="transaction"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="buffered"></param>
        /// <returns></returns>
        IEnumerable<T> GetList(object predicate, IList<ISort> sort = null, int? commandTimeout = null, bool buffered = false);

        /// <summary>
        /// List<ISort> sortList = new List<ISort>();  //排序
        /// sortList.Add(Predicates.Sort<myPoco>(x => x.Name, false));
        /// var result = GetList<myPoco>(null, sortList).ToList();
        /// return result;
        /// protected IEnumerable<T> GetList<T>(object predicate, IList<ISort> sort = null, 
        ///   IDbTransaction transaction = null, int? commandTimeout = null, bool buffered = false) where T : class {
        ///   var result = connection.GetList<T>(predicate, sort, transaction, commandTimeout, buffered);
        ///   return result;
        /// }
        /// </summary>
        /// <param name="predicate">参数： var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true);</param>
        /// <param name="sort"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="transaction"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="buffered"></param>
        /// <returns></returns>
        PagedResultOutput<T> GetPage(object predicate, IList<ISort> sort = null, int pageIndex = 1, int pageSize = 20, int? commandTimeout = null, bool buffered = false);

        /// <summary>
        /// string sql = "userinfo_insert";  //或者 insert into userinfo (name, phone) values(@login_name, @phone);
        /// using (var conn = GetConnectionFactory()) {
        ///   var rowCounts = conn.Execute(sql,
        ///   new { login_name = "tom", phone = "13800000000" },
        ///   commandType: CommandType.StoredProcedure);  // CommandType.Text
        ///   }
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="commandType"></param>
        /// <param name="transaction"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        int Execute(string sql, object param = null, CommandType commandType = CommandType.Text, int? commandTimeout = null);

        T Get(long id);

        IList<T> GetAll();

        void Insert(T obj);

        void Update(T obj);

        void Delete(T obj);
    }
}